<template>
  <div id="recruitTable">
    <el-dialog title="退回原因" :visible.sync="backFormVisible" :close-on-click-modal="false" width="700px" :close-on-press-escape="false">
      <el-form :model="backForm" ref="backForm" :inline="true" inline-message>
        <el-form-item prop="remark">
          <el-input v-model="backForm.remark" style="width:600px"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click.native="submitBack(backForm.id)" :loading="btnLoading">提交</el-button>
        <el-button @click.native="backFormVisible = false">取消</el-button>
      </div>
    </el-dialog>
    <el-radio-group v-model="status" style="margin-bottom:10px">
      <el-radio-button :label="1">制度备案</el-radio-button>
      <el-radio-button :label="2">人员备案</el-radio-button>
    </el-radio-group>
    <div v-show="status===1">
      <el-dialog :title="dialogTitle" :visible.sync="editFormVisible" width="98%" top="20px">
        <el-form :model="editForm" label-width="200px" ref="editForm" :inline="true" style="padding:10px 0 0;clear:both" :rules="editFormRules">
          <table cellspacing="0" cellpadding="0" class="mytable">
            <tr>
              <th style="width:120px; vertical-align: middle;">批复时间</th>
              <td style="vertical-align: middle;">
                <el-form-item prop="docDate" v-if="editFlag">
                  <el-date-picker
                    v-model="editForm.docDate"
                    value-format="yyyy-MM-dd"
                    type="date"
                    placeholder="选择日期">
                  </el-date-picker>
                </el-form-item>
                <span v-else>{{editForm.docDate}}</span>
              </td>
              <th style="width:120px; vertical-align: middle;">批复文号</th>
              <td style="vertical-align: middle;">
                <el-form-item prop="docNum" v-if="editFlag">
                  <el-input v-model="editForm.docNum" style="width:200px"></el-input>
                </el-form-item>
                <span v-else>{{editForm.docNum}}</span>
              </td>
            </tr>
            <tr>
              <th colspan="1" style="width:120px; vertical-align: middle;">PDF附件</th>
              <td colspan="3" style="vertical-align: middle;">
                <div v-if="editFlag">
                  <el-upload
                    style="width:800px;margin-bottom:10px;"
                    ref="upload1"
                    :action="this.$http.defaults.baseURL+this.$http.defaults.postAPI +'api/cadrePostGenFileInfo/upload'"
                    :on-success="handleUploadSucc"
                    :on-remove="handleRemove"
                    :before-remove="beforeRemove"
                    :on-error="uploadError"
                    :before-upload="beforeUpload"
                    accept="application/pdf"
                    :limit="1"
                    :on-exceed="handleExceed"
                    :file-list="fileList"
                  >
                    <el-button type="primary" :loading="saveloading">上传</el-button>
                    <div slot="tip" class="el-upload__tip">注：只支持上传pdf文件</div>
                  </el-upload>
                </div>
                <div v-else>
                  <template v-if="editForm.files&&editForm.files.length>0">
                    <div v-for="item in editForm.files" :key="'detailfile_'+item.id" style="height:40px;line-height:40px">
                      <a href="javascript:void(0)" @click="download(item.id)"><i class="el-icon-paperclip" /> {{item.fileName}}.{{item.fileType}}</a>
                    </div>
                  </template>
                </div>
              </td>
            </tr>
          </table>
          <el-button type="primary" @click.native="editFormSubmit" :loading="saveloading" v-if="editFlag">提交</el-button>
        </el-form>
      </el-dialog>
      <div v-if="canEdit" style="height:50px">
        <el-button icon="el-icon-plus" type="success" style="float:right" @click="handleAdd()">新增</el-button>
      </div>
      <el-table :data="list1" highlight-current-row v-loading="listLoading" style="width: 100%;margin-bottom: 20px;">
        <el-table-column prop="docDate" label="批复时间" width="150" align="center">
        </el-table-column>
        <el-table-column prop="docNum" label="批复文号" width="250" align="center">
        </el-table-column>
        <el-table-column prop="pdf" min-width="320" label="PDF附件">
          <template slot-scope="scope">
            <div v-for="item in scope.row.files" :key="'file_'+item.id"><a href="javascript:void(0)" @click="download(item.id)"><i class="el-icon-paperclip" /> {{ item.fileName }}.{{ item.fileType }}</a></div>
          </template>
        </el-table-column>
        <el-table-column prop="state" width="200" label="状态" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.state===1">已提交</span>
            <span v-else-if="scope.row.state===2">已退回<span v-if="scope.row.remark">(原因:{{scope.row.remark}})</span></span>
            <span v-else-if="scope.row.state===0">未提交</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="260" v-if="canEdit">
          <template slot-scope="scope">
            <template>
              <el-button v-if="scope.row.state!==1" @click="setState(scope.row.id,1)" size="small" type="success" :loading="btnLoading">
                提交备案
              </el-button>
              <el-dropdown split-button v-if="scope.row.state!==1" @click="handleDetail(scope.row,0)" size="small" type="primary" :loading="btnLoading">
                查看
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item @click.native="handleDetail(scope.row,1)" >修改</el-dropdown-item>
                  <el-dropdown-item @click.native="handleDel(scope.row.id)" >删除</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
              <el-button v-else @click="handleDetail(scope.row,0)" size="small" type="primary">
                查看
              </el-button>
            </template>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="220" v-else key="detail">
          <template slot-scope="scope">
            <template>
              <el-button @click="showBack(scope.row.id,1)" size="small" type="danger" :loading="btnLoading">
                退回
              </el-button>
              <el-button @click="handleDetail(scope.row,0)" size="small" type="primary">查看</el-button>
            </template>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div v-show="status===2">
      <el-dialog :title="dialogTitle" :visible.sync="editFormVisible2" width="98%" top="20px">
        <el-form :model="editForm2" label-width="200px" ref="editForm2" :inline="true" style="padding:10px 0 0;clear:both" :rules="editFormRules2">
          <table cellspacing="0" cellpadding="0" class="mytable">
            <tr>
              <th style="width:120px; vertical-align: middle;">姓名</th>
              <td style="vertical-align: middle;">
                <el-form-item prop="realName" v-if="editFlag">
                  <el-input v-model="editForm2.realName" style="width:200px"></el-input>
                </el-form-item>
                <span v-else>{{editForm2.realName}}</span>
              </td>
              <th style="width:120px; vertical-align: middle;">身份证号</th>
              <td style="vertical-align: middle;">
                <el-form-item prop="idCardNo" v-if="editFlag">
                  <el-input v-model="editForm2.idCardNo" style="width:200px"></el-input>
                </el-form-item>
                <span v-else>{{editForm2.idCardNo}}</span>
              </td>
            </tr>
            <tr>
              <th style="width:120px; vertical-align: middle;">性别</th>
              <td style="vertical-align: middle;">
                <el-form-item prop="gender" v-if="editFlag">
                  <el-select v-model="editForm2.gender">
                    <el-option :value="1" label="男" />
                    <el-option :value="2" label="女" />
                  </el-select>
                </el-form-item>
                <span v-else>{{editForm2.gender===1?'男':'女'}}</span>
              </td>
              <th style="width:120px; vertical-align: middle;">出生日期</th>
              <td style="vertical-align: middle;">
                <el-form-item prop="birthday" v-if="editFlag">
                  <el-date-picker
                    v-model="editForm2.birthday"
                    value-format="yyyy-MM-dd"
                    type="date"
                    placeholder="选择日期">
                  </el-date-picker>
                </el-form-item>
                <span v-else>{{editForm2.birthday}}</span>
              </td>
            </tr>
            <tr>
              <th style="width:120px; vertical-align: middle;">最高学历</th>
              <td style="vertical-align: middle;">
                <el-form-item prop="education" v-if="editFlag">
                  <el-select v-model="editForm2.education">
                    <el-option v-for="(item,index) in educationList" :key="'education'+index" :value="item" :label="item" />
                  </el-select>
                </el-form-item>
                <span v-else>{{editForm2.education}}</span>
              </td>
              <th style="width:120px; vertical-align: middle;">最高学位</th>
              <td style="vertical-align: middle;">
                <el-form-item prop="degree" v-if="editFlag">
                  <el-select v-model="editForm2.degree">
                    <el-option v-for="(item,index) in degreeList" :key="'education'+index" :value="item" :label="item" />
                  </el-select>
                </el-form-item>
                <span v-else>{{editForm2.degree}}</span>
              </td>
            </tr>
            <tr>
              <th style="width:120px; vertical-align: middle;">职称</th>
              <td style="vertical-align: middle;" colspan="3">
                <el-form-item prop="jobTitle" v-if="editFlag">
                  <el-select v-model="editForm2.jobTitle">
                    <el-option v-for="(item,index) in jobTitleList" :key="'education'+index" :value="item" :label="item" />
                  </el-select>
                </el-form-item>
                <span v-else>{{editForm2.jobTitle}}</span>
              </td>
            </tr>
            <tr>
              <th style="width:120px; vertical-align: middle;">毕业院校及专业<br>（从本科阶段填起）</th>
              <td style="vertical-align: middle;" colspan="3">
                <el-form-item prop="school" v-if="editFlag">
                  <el-input type="textarea" :rows="3" v-model="editForm2.school" style="width:800px" maxlength="200" show-word-limit></el-input>
                </el-form-item>
                <span v-else>{{editForm2.school}}</span>
              </td>
            </tr>
            <tr>
              <th style="width:120px; vertical-align: middle;">单位</th>
              <td style="vertical-align: middle;">
                <el-form-item prop="unitName" v-if="editFlag">
                  <el-input v-model="editForm2.unitName" style="width:400px"></el-input>
                </el-form-item>
                <span v-else>{{editForm2.unitName}}</span>
              </td>
              <th style="width:120px; vertical-align: middle;">现任职务</th>
              <td style="vertical-align: middle;">
                <el-form-item prop="job" v-if="editFlag">
                  <el-input v-model="editForm2.job" style="width:200px"></el-input>
                </el-form-item>
                <span v-else>{{editForm2.job}}</span>
              </td>
            </tr>
            <tr>
              <th style="width:120px; vertical-align: middle;">研究方向</th>
              <td style="vertical-align: middle;" colspan="3">
                <el-form-item prop="researchDirection" v-if="editFlag">
                  <el-input type="textarea" :rows="3" v-model="editForm2.researchDirection" style="width:800px" maxlength="200" show-word-limit></el-input>
                </el-form-item>
                <span v-else>{{editForm2.researchDirection}}</span>
              </td>
            </tr>
            <tr>
              <th style="width:120px; vertical-align: middle;">代表性科技成果</th>
              <td style="vertical-align: middle;" colspan="3">
                <el-form-item prop="achievements" v-if="editFlag">
                  <el-input type="textarea" :rows="3" v-model="editForm2.achievements" style="width:800px" maxlength="200" show-word-limit></el-input>
                </el-form-item>
                <span v-else>{{editForm2.achievements}}</span>
              </td>
            </tr>
            <tr>
              <th style="width:120px; vertical-align: middle;">国内外学术组织任职情况</th>
              <td style="vertical-align: middle;" colspan="3">
                <el-form-item prop="organizationPositions" v-if="editFlag">
                  <el-input type="textarea" :rows="3" v-model="editForm2.organizationPositions" style="width:800px" maxlength="200" show-word-limit></el-input>
                </el-form-item>
                <span v-else>{{editForm2.organizationPositions}}</span>
              </td>
            </tr>
            <tr>
              <th style="width:120px; vertical-align: middle;">入选人才工程情况</th>
              <td style="vertical-align: middle;" colspan="3">
                <el-form-item prop="talentProjects" v-if="editFlag">
                  <el-input type="textarea" :rows="3" v-model="editForm2.talentProjects" style="width:800px" maxlength="200" show-word-limit></el-input>
                </el-form-item>
                <span v-else>{{editForm2.talentProjects}}</span>
              </td>
            </tr>
            <tr>
              <th style="width:120px; vertical-align: middle;">是否占用技术二级岗位</th>
              <td style="vertical-align: middle;">
                <el-form-item prop="useTechPost2" v-if="editFlag">
                  <el-select v-model="editForm2.useTechPost2">
                    <el-option :value="1" label="是" />
                    <el-option :value="0" label="否" />
                  </el-select>
                </el-form-item>
                <span v-else>{{editForm2.useTechPost2?'是':'否'}}</span>
              </td>
              <th style="width:120px; vertical-align: middle;">占用指标类型</th>
              <td style="vertical-align: middle;">
                <el-form-item prop="postType" v-if="editFlag">
                  <el-select v-model="editForm2.postType" @change="changePostType()">
                    <el-option v-for="(item,index) in postTypeList" :key="'education'+index" :value="index+1" :label="item" />
                  </el-select>
                </el-form-item>
                <span v-else>{{postTypeList[editForm2.postType-1]}}</span>
              </td>
            </tr>
            <tr>
              <th style="width:120px; vertical-align: middle;">依据文号</th>
              <td style="vertical-align: middle;">
                <el-form-item prop="postId" v-if="editFlag">
                  <el-select v-model="editForm2.postId" v-loading="selectLoading" :disabled="selectLoading">
                    <el-option v-for="(item,index) in docList" :key="'education'+index" :value="item.id" :label="item.docNum" />
                  </el-select>
                </el-form-item>
                <span v-else>{{editForm2.docNum}}</span>
              </td>
              <th style="width:120px; vertical-align: middle;">本聘期起止时间</th>
              <td style="vertical-align: middle;">
                <el-form-item prop="docDate" v-if="editFlag">
                  <el-date-picker
                    v-model="editForm2.docDate"
                    type="daterange"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    value-format="yyyy-MM-dd"
                  >
                  </el-date-picker>
                </el-form-item>
                <span v-else>{{editForm2.docDate[0]}}至{{editForm2.docDate[1]}}</span>
              </td>
            </tr>
            <tr>
              <th style="width:120px; vertical-align: middle;">是否在岗</th>
              <td style="vertical-align: middle;">
                <el-form-item prop="inPost" v-if="editFlag">
                  <el-select v-model="editForm2.inPost">
                    <el-option :value="1" label="是" />
                    <el-option :value="0" label="否" />
                  </el-select>
                </el-form-item>
                <span v-else>{{editForm2.inPost?'是':'否'}}</span>
              </td>
              <th style="width:120px; vertical-align: middle;">备案时间</th>
              <td style="vertical-align: middle;">
                <el-form-item prop="addDate" v-if="editFlag">
                  <el-date-picker
                    v-model="editForm2.addDate"
                    value-format="yyyy-MM-dd"
                    type="date"
                    placeholder="选择日期">
                  </el-date-picker>
                </el-form-item>
                <span v-else>{{editForm2.addDate}}</span>
              </td>
            </tr>
          </table>
          <el-button type="primary" @click.native="editFormSubmit2" :loading="saveloading" v-if="editFlag">提交</el-button>
        </el-form>
      </el-dialog>
      <!-- <div v-if="canEdit" style="height:50px"> -->
        <!-- <el-button icon="el-icon-upload2" type="success" style="float:right">批量导入</el-button>
        <el-button icon="el-icon-download" type="primary" style="float:right;margin-right:10px">下载模板</el-button> -->
        <el-button v-if="canEdit" icon="el-icon-plus" type="success" style="float:right" @click="handleAdd2()">新增</el-button>
        <!-- <el-button icon="el-icon-document-copy" type="primary" style="float:right;">初始化</el-button> -->
      <!-- </div> -->
      <!-- <div v-else> -->
        <el-button v-else icon="el-icon-download" type="primary" style="float:right">导出</el-button>
      <!-- </div> -->
      <h1 style="text-align:center">专业技术二级岗位人员情况表</h1>
      <el-form :inline="true" :model="filters" style="margin-top:20px">
        <div>
          <el-form-item label="单位名称">
            <el-input v-model="filters.unitName"></el-input>
          </el-form-item>
          <el-form-item label="姓名">
            <el-input v-model="filters.realName"></el-input>
          </el-form-item>
          <el-form-item>
            <el-checkbox v-model="filters.inPost">只显示当前在岗人员</el-checkbox>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="searchList" icon="el-icon-search">查询</el-button>
          </el-form-item>
        </div>
      </el-form>
      <el-table :data="list2" highlight-current-row v-loading="listLoading" style="width: 100%;margin-bottom: 20px;" row-key="id">
        <el-table-column prop="realName" width="200" label="姓名">
        </el-table-column>
        <!-- <el-table-column prop="idCardNo" width="100" label="身份证号" align="center" >
        </el-table-column>
        <el-table-column prop="gender" width="50" label="性别" align="center">
          <template slot-scope="scope">
            {{scope.row.gender===2?'男':'女'}}
          </template>
        </el-table-column>
        <el-table-column prop="birthday" width="100" label="出生日期" align="center" /> -->
        <el-table-column prop="education" width="80" label="最高学历" align="center" />
        <el-table-column prop="degree" width="80" label="最高学位" align="center" />
        <el-table-column prop="jobTitle" width="60" label="职称" align="center" />
        <!-- <el-table-column prop="school" width="100" label="毕业院校及专业 从本科阶段填起" /> -->
        <el-table-column prop="unitName" label="单位" min-width="80">
        </el-table-column>
        <el-table-column prop="job" width="80" label="现任职务" />
        <!-- <el-table-column prop="direct" width="80" label="研究方向" />
        <el-table-column prop="kj" width="80" label="代表性科技成果" />
        <el-table-column prop="rz" width="80" label="国内外学术组织任职情况" />
        <el-table-column prop="rc" width="80" label="入选人才工程情况" /> -->
        <el-table-column prop="useTechPost2" width="80" label="是否占用技术二级岗位" align="center" >
          <template slot-scope="scope">
            {{scope.row.useTechPost2?'是':'否'}}
          </template>
        </el-table-column>
        <el-table-column prop="postType" width="130" label="占用指标类型" align="center">
          <template slot-scope="scope">
            {{postTypeList[scope.row.postType-1]}}
          </template>
        </el-table-column>
        <el-table-column prop="docNum" width="80" label="依据文号" align="center" >
        </el-table-column>
        <el-table-column prop="date" width="210" label="本聘期起止时间" align="center">
          <template slot-scope="scope">
            {{scope.row.startDate}}至{{scope.row.endDate}}
          </template>
        </el-table-column>
        <el-table-column prop="inPost" width="60" label="是否在岗" align="center" >
          <template slot-scope="scope">
            {{scope.row.inPost?'是':'否'}}
          </template>
        </el-table-column>
        <el-table-column prop="addDate" width="110" label="备案时间" align="center" >
        </el-table-column>
        <el-table-column prop="state" width="200" label="状态" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.state===1">已提交</span>
            <span v-else-if="scope.row.state===2">已退回<span v-if="scope.row.remark">(原因:{{scope.row.remark}})</span></span>
            <span v-else-if="scope.row.state===0">未提交</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="260" v-if="canEdit">
          <template slot-scope="scope">
            <template>
              <el-button v-if="scope.row.state!==1" @click="setState2(scope.row.id,1)" size="small" type="success" :loading="btnLoading">
                提交备案
              </el-button>
              <el-dropdown split-button v-if="scope.row.state!==1" @click="handleDetail2(scope.row,0)" size="small" type="primary" :loading="btnLoading">
                查看
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item @click.native="handleDetail2(scope.row,1)" >修改</el-dropdown-item>
                  <el-dropdown-item @click.native="handleDel2(scope.row.id)" >删除</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
              <el-button v-else @click="handleDetail2(scope.row,0)" size="small" type="primary">
                查看
              </el-button>
            </template>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="220" v-else key="detail">
          <template slot-scope="scope">
            <template>
              <el-button @click="showBack(scope.row.id,2)" size="small" type="danger" :loading="btnLoading">
                退回
              </el-button>
              <el-button @click="handleDetail2(scope.row,0)" size="small" type="primary">查看</el-button>
            </template>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination :total="totalnum" :page-size="pageSize" @current-change="handleCurrentChange" :current-page="pageNum" @size-change="handleSizeChange" :page-sizes="[10, 20, 30, 50]" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
const defaultForm = {
  id: null,
  state: 0,
  docDate: '',
  docNum: '',
  files: []
}
const defaultForm2 = {
  id: null,
  state: 0,
  realName: '',
  idCardNo: '',
  gender: null,
  birthday: '',
  education: '',
  degree: '',
  jobTitle: '',
  school: '',
  unitName: '',
  job: '',
  researchDirection: '',
  achievements: '',
  organizationPositions: '',
  talentProjects: '',
  useTechPost2: null,
  postType: null,
  postId: null,
  docDate: [],
  inPost: null,
  addDate: '',
  startDate: '',
  endDate: ''
}
export default {
  props: {
    timestamp: '',
    canEdit: null,
    canAudit: null,
    unitId: null
  },
  watch: {
    timestamp: {
      handler (val) {
        this.loaddata()
      },
      immediate: true
    },
    unitId: {
      handler (val) {
        this.loaddata()
      },
      immediate: true
    },
    canEdit: {
      handler (val) {
        console.log(val)
      },
      immediate: true
    }
  },
  data () {
    return {
      showBackFlag: null,
      selectLoading: false,
      pageNum: 1,
      pageSize: 20,
      totalnum: 0,
      educationList: ['研究生', '大学本科', '大学专科', '中专', '高中及以下'],
      degreeList: ['学士', '硕士', '博士'],
      jobTitleList: ['正高', '副高', '中级', '初级', '空'],
      postTypeList: ['基础性指标', '科技人才奖励指标', '部统筹指标'],
      docList: [],
      fileList: [],
      backForm: {remark: '', id: null},
      backFormVisible: false,
      btnLoading: false,
      editFormVisible: false,
      editFormVisible2: false,
      dialogTitle: '新增',
      isOut: false,
      saveloading: false,
      editFormRules: {
        docDate: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        docNum: [
          { required: true, message: '必填', trigger: 'blur' }
        ]
      },
      editFormRules2: {
        realName: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        idCardNo: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        gender: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        birthday: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        education: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        degree: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        jobTitle: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        school: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        unitName: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        job: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        researchDirection: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        achievements: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        organizationPositions: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        talentProjects: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        useTechPost2: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        postType: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        postId: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        docDate: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        inPost: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        addDate: [
          { required: true, message: '必填', trigger: 'blur' }
        ]
      },
      editFlag: 0,
      listLoading: false,
      unitName: '',
      editForm: Object.assign({}, defaultForm),
      editForm2: Object.assign({}, defaultForm2),
      getRowKeys (row) {
        return row.id
      },
      list1: [
      ],
      list2: [
      ],
      status: 1,
      filters: {unitName: '', realName: '', inPost: true},
      drawer: false,
      addFormVisible1: false,
      addFormVisible2: false,
      startYear: '2021',
      list: []
    }
  },
  methods: {
    submitBack (id) {
      if (this.showBackFlag === 1) {
        this.setState(id, 2)
      } else if (this.showBackFlag === 2) {
        this.setState2(id, 2)
      }
    },
    searchList () {
      this.pageNum = 1
      this.getList2()
    },
    handleSizeChange (val) {
      this.changeSizeFlag = true
      this.pageNum = 1
      this.pageSize = val
      this.getList2()
    },
    handleCurrentChange (val) {
      if (this.changeSizeFlag === false) {
        this.pageNum = val
        this.getList2()
      }
    },
    changePostType (flag, obj) {
      console.log(obj)
      this.docList = []
      this.editForm2.postId = null
      this.selectLoading = true
      if (flag) {
        this.editForm2 = Object.assign({}, obj)
        this.editForm2.docDate = [this.editForm2.startDate, this.editForm2.endDate]
        console.log(this.editForm2)
      }
      if (this.editForm2.postType === 1) {
        let tableName = 'cadrePostBusPostPlan'
        let para = {
          pageNum: 1,
          pageSize: 1000,
          unitId: this.unitId,
          state: 1
        }
        this.$http.post(this.$http.defaults.postAPI + 'api/' + tableName + '/queryByPage', para).then(response => {
          this.selectLoading = false
          if (response.data.success === true) {
            this.docList = response.data.result.records
            if (flag) {
              this.editForm2 = Object.assign({}, obj)
              this.editForm2.docDate = [this.editForm2.startDate, this.editForm2.endDate]
              console.log(this.editForm2)
            }
          } else {
            console.log('获取数据失败:' + response.data.message)
            this.$message({
              message: '获取数据失败:' + response.data.message,
              type: 'error'
            })
          }
        }).catch(error => {
          this.selectLoading = false
          console.log(error)
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
      } else if (this.editForm2.postType === 2) {
        let tableName = 'cadrePostBusTalentsPost'
        let para = {
          unitId: this.unitId,
          state: 1
        }
        this.$http.post(this.$http.defaults.postAPI + 'api/' + tableName + '/queryList', para).then(response => {
          this.selectLoading = false
          if (response.data.success === true) {
            this.docList = response.data.result
            if (flag) {
              this.editForm2 = Object.assign({}, obj)
              this.editForm2.docDate = [this.editForm2.startDate, this.editForm2.endDate]
              console.log(this.editForm2)
            }
          } else {
            console.log('获取数据失败:' + response.data.message)
            this.$message({
              message: '获取数据失败:' + response.data.message,
              type: 'error'
            })
          }
        }).catch(error => {
          this.selectLoading = false
          console.log(error)
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
      } else if (this.editForm2.postType === 3) {
        let tableName = 'cadrePostBusAchievementsPost'
        let para = {
          unitId: this.unitId,
          state: 1
        }
        this.$http.post(this.$http.defaults.postAPI + 'api/' + tableName + '/queryList', para).then(response => {
          this.selectLoading = false
          if (response.data.success === true) {
            this.docList = response.data.result.list
            if (flag) {
              this.editForm2 = Object.assign({}, obj)
              this.editForm2.docDate = [this.editForm2.startDate, this.editForm2.endDate]
              console.log(this.editForm2)
            }
          } else {
            console.log('获取数据失败:' + response.data.message)
            this.$message({
              message: '获取数据失败:' + response.data.message,
              type: 'error'
            })
          }
        }).catch(error => {
          this.selectLoading = false
          console.log(error)
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
      }
    },
    showBack (id, flag) {
      this.showBackFlag = flag
      this.backFormVisible = true
      this.backForm.remark = ''
      this.backForm.id = id
    },
    beforeUpload (file) {
      const isFormat = file.name.indexOf('.pdf') > 0 || file.name.indexOf('.PDF') > 0
      const isLt500M = file.size / 1024 / 1024 < 60
      if (!isLt500M) {
        this.$message.error('单个附件不能超过60M!')
      } else {
        this.saveloading = true
      }
      if (!isFormat) {
        this.$message.error('附件格式必须为pdf!')
      } else {
        this.saveloading = true
      }
      return isFormat && isLt500M
    },
    async handleUploadSucc (response, file, fileList) {
      this.saveloading = false
      if (response.success) {
        let obj = response.result[0]
        this.fileList.push({id: obj.id, name: obj.fileName + '.' + obj.fileType, url: this.$http.defaults.baseURL + this.$http.defaults.postAPI + 'api/cadrePostGenFileInfo/download?id=' + obj.id})
        this.$message({
          message: '上传成功！',
          type: 'success'
        })
      } else {
        this.$message({
          message: '上传失败:' + response.message,
          type: 'error'
        })
      }
    },
    beforeRemove (file) {
      if (file && file.status === 'success') {
        return this.$confirm(`确定删除 ${file.name}？`)
      }
    },
    handleRemove (file, fileList) {
      console.log('file')
      console.log(file)
      if (file && file.status === 'success') {
        let fileid = file.id ? file.id : file.response.result[0].id
        this.fileList = this.fileList.filter(item => item.id !== fileid)
        this.$message({
          message: '删除成功！',
          type: 'success'
        })
      }
    },
    uploadError (err) {
      this.saveloading = false
      console.log(err)
      this.$message({
        message: '上传失败:' + err,
        type: 'error'
      })
    },
    download (id) {
      window.open(this.$http.defaults.baseURL + this.$http.defaults.postAPI + 'api/cadrePostGenFileInfo/download?id=' + id)
    },
    handleExceed (files, fileList) {
      this.$message.warning(`最多上传1个文件`)
    },
    handleDel (id) {
      this.$confirm('确认删除该记录吗?', '提示', {
        type: 'warning'
      }).then(() => {
        let tableName = 'cadrePostBusDocReg'
        let para = {ids: [id]}
        this.listLoading = true
        this.$http.post(this.$http.defaults.postAPI + 'api/' + tableName + '/remove', para).then(response => {
          if (response.data.success === true) {
            this.addLoading = false
            this.$message({
              message: '删除成功',
              type: 'success'
            })
          } else {
            console.log('删除失败:' + response.data.message)
            this.$message({
              message: '删除失败:' + response.data.message,
              type: 'error'
            })
          }
          this.getList()
        })
          .catch(error => {
            this.addLoading = false
            console.log(error)
            this.$message({
              message: '删除失败:' + error,
              type: 'error'
            })
          })
      })
    },
    handleDel2 (id) {
      this.$confirm('确认删除该记录吗?', '提示', {
        type: 'warning'
      }).then(() => {
        let tableName = 'cadrePostBusPersonReg'
        let para = {ids: [id]}
        this.listLoading = true
        this.$http.post(this.$http.defaults.postAPI + 'api/' + tableName + '/remove', para).then(response => {
          if (response.data.success === true) {
            this.addLoading = false
            this.$message({
              message: '删除成功',
              type: 'success'
            })
          } else {
            console.log('删除失败:' + response.data.message)
            this.$message({
              message: '删除失败:' + response.data.message,
              type: 'error'
            })
          }
          this.getList2()
        })
          .catch(error => {
            this.addLoading = false
            console.log(error)
            this.$message({
              message: '删除失败:' + error,
              type: 'error'
            })
          })
      })
    },
    setState (id, state) {
      this.$confirm('确认' + (state === 1 ? '提交' : '退回') + '吗?', '提示', {
        type: 'warning'
      }).then(() => {
        let tableName = 'cadrePostBusDocReg'
        let para = {
          id: id,
          state: state
        }
        if (state === 2) {
          para.remark = this.backForm.remark
        }
        this.btnLoading = true
        this.$http.post(this.$http.defaults.postAPI + 'api/' + tableName + '/save', para).then(response => {
          this.btnLoading = false
          if (response.data.success === true) {
            this.$message({
              message: '操作成功',
              type: 'success'
            })
            this.getList()
            this.backFormVisible = false
          } else {
            console.log('操作失败:' + response.data.message)
            this.$message({
              message: '操作失败:' + response.data.message,
              type: 'error'
            })
          }
        }).catch(error => {
          this.btnLoading = false
          console.log(error)
          this.$message({
            message: '操作失败:' + error,
            type: 'error'
          })
        })
      })
    },
    setState2 (id, state) {
      this.$confirm('确认' + (state === 1 ? '提交' : '退回') + '吗?', '提示', {
        type: 'warning'
      }).then(() => {
        let tableName = 'cadrePostBusPersonReg'
        let para = {
          id: id,
          state: state
        }
        if (state === 2) {
          para.remark = this.backForm.remark
        }
        this.btnLoading = true
        this.$http.post(this.$http.defaults.postAPI + 'api/' + tableName + '/save', para).then(response => {
          this.btnLoading = false
          if (response.data.success === true) {
            this.$message({
              message: '操作成功',
              type: 'success'
            })
            this.getList2()
            this.backFormVisible = false
          } else {
            console.log('操作失败:' + response.data.message)
            this.$message({
              message: '操作失败:' + response.data.message,
              type: 'error'
            })
          }
        }).catch(error => {
          this.btnLoading = false
          console.log(error)
          this.$message({
            message: '操作失败:' + error,
            type: 'error'
          })
        })
      })
    },
    handleAdd () {
      this.dialogTitle = '新增'
      this.editForm = Object.assign({}, defaultForm)
      this.fileList = []
      this.editFormVisible = true
      this.editFlag = 1
    },
    handleAdd2 () {
      this.dialogTitle = '新增'
      this.editForm2 = Object.assign({}, defaultForm2)
      this.editFormVisible2 = true
      this.editFlag = 1
    },
    handleDetail (obj, editFlag) {
      this.dialogTitle = editFlag ? '修改' : '详情'
      this.editForm = Object.assign({}, obj)
      this.fileList = []
      if (this.editForm.files) {
        this.editForm.files.forEach(item => {
          this.fileList.push({id: item.id, name: item.fileName + '.' + item.fileType, url: this.$http.defaults.baseURL + this.$http.defaults.postAPI + 'api/cadrePostGenFileInfo/download?id=' + item.id})
        })
      }
      this.editFormVisible = true
      this.editFlag = editFlag
    },
    handleDetail2 (obj, editFlag) {
      this.dialogTitle = editFlag ? '修改' : '详情'
      this.editForm2 = Object.assign({}, defaultForm2)
      console.log(editFlag)
      if (editFlag) {
        console.log('changePostType')
        this.$nextTick(() => {
          this.changePostType(1, obj)
        })
      } else {
        this.editForm2 = Object.assign({}, obj)
        this.editForm2.docDate = [this.editForm2.startDate, this.editForm2.endDate]
      }
      this.editFormVisible2 = true
      this.editFlag = editFlag
    },
    editFormSubmit () {
      this.$refs.editForm.validate((valid) => {
        if (valid) {
          this.saveloading = true
          let para = Object.assign({}, this.editForm)
          para.unitId = this.unitId
          para.fileIds = this.fileList.map(item => item.id)
          console.log(para)
          let tableName = 'cadrePostBusDocReg'
          this.$http.post(this.$http.defaults.postAPI + 'api/' + tableName + '/save', para).then(response => {
            console.log(response.data.success)
            this.saveloading = false
            if (response.data.success === true) {
              this.$message({
                message: '提交成功',
                type: 'success'
              })
              this.editFormVisible = false
              this.getList()
            } else {
              console.log('提交失败:' + response.data.message)
              this.$message({
                message: '提交失败:' + response.data.message,
                type: 'error'
              })
            }
          }).catch(error => {
            console.log(error)
            this.$message({
              message: '提交失败:' + error,
              type: 'error'
            })
            this.saveloading = false
          })
        }
      })
    },
    editFormSubmit2 () {
      this.$refs.editForm2.validate((valid) => {
        if (valid) {
          this.saveloading = true
          let para = Object.assign({}, this.editForm2)
          para.unitId = this.unitId
          if (para.docDate.length > 0) {
            para.startDate = para.docDate[0]
            para.endDate = para.docDate[1]
            para.docDate = null
          }
          let tableName = 'cadrePostBusPersonReg'
          this.$http.post(this.$http.defaults.postAPI + 'api/' + tableName + '/save', para).then(response => {
            console.log(response.data.success)
            this.saveloading = false
            if (response.data.success === true) {
              this.$message({
                message: '提交成功',
                type: 'success'
              })
              this.editFormVisible2 = false
              this.getList2()
            } else {
              console.log('提交失败:' + response.data.message)
              this.$message({
                message: '提交失败:' + response.data.message,
                type: 'error'
              })
            }
          }).catch(error => {
            console.log(error)
            this.$message({
              message: '提交失败:' + error,
              type: 'error'
            })
            this.saveloading = false
          })
        }
      })
    },
    getList () {
      if (this.unitId) {
        let tableName = 'cadrePostBusDocReg'
        this.listLoading = true
        let para = {
          pageNum: 1,
          pageSize: 1000,
          unitId: this.unitId
        }
        if (!this.canEdit) {
          para.state = 1
        }
        this.$http.post(this.$http.defaults.postAPI + 'api/' + tableName + '/queryByPage', para).then(response => {
          this.listLoading = false
          if (response.data.success === true) {
            this.list1 = response.data.result.records
          } else {
            console.log('获取数据失败:' + response.data.message)
            this.$message({
              message: '获取数据失败:' + response.data.message,
              type: 'error'
            })
          }
        }).catch(error => {
          console.log(error)
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
          this.listLoading = false
        })
      }
    },
    getList2 () {
      if (this.unitId) {
        let tableName = 'cadrePostBusPersonReg'
        this.listLoading = true
        let para = {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          unitId: this.unitId,
          unitName: this.filters.unitName,
          realName: this.filters.realName,
          inPost: this.filters.inPost ? 1 : null
        }
        let url = this.$http.defaults.postAPI + 'api/' + tableName + '/queryGroupByPage'
        if (this.isOut) {
          para.isOut = 0
        }
        if (!this.canEdit) {
          para.state = 1
        }
        this.$http.post(url, para).then(response => {
          this.listLoading = false
          if (response.data.success === true) {
            this.list2 = response.data.result.records
            this.totalnum = response.data.result.total
            // this.list2.forEach((item, index) => {
            //   if (item.children && item.children.length > 0) {
            //     this.list2[index].hasChildren = true
            //   }
            // })
          } else {
            console.log('获取数据失败:' + response.data.message)
            this.$message({
              message: '获取数据失败:' + response.data.message,
              type: 'error'
            })
          }
        }).catch(error => {
          console.log(error)
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
          this.listLoading = false
        })
      }
    },
    loaddata () {
      this.getList()
      this.getList2()
    }
  }
}
</script>
<style scoped>
  .mytable{
    border-top: 1px solid #74a6cc;
    border-left: 1px solid #74a6cc;
    margin:0 10px 10px;
    width: calc(100% - 20px);
  }
  .mytable th{
    padding: 10px;
    border-right: 1px solid #74a6cc;
    border-bottom: 1px solid #74a6cc;
    vertical-align: top;
    line-height: 150%;
    background: #FAFAFA;
    width:200px;
    text-align:right;
  }
  .mytable td{
    padding: 10px;
    border-right: 1px solid #74a6cc;
    border-bottom: 1px solid #74a6cc;
    vertical-align: top;
    line-height: 150%;
  }
</style>
<style>
#recruitTable .el-table{
  border:1px solid #95B8E7 !important;
}
#recruitTable .el-table td, #recruitTable .el-table th{
  border-right:1px solid #95B8E7 !important;
  border-bottom:1px solid #95B8E7 !important;
}
</style>
